{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane"> 
        <div class="layui-form-item">
            <label class="layui-form-label">所属类型</label>
            <div class="layui-input-4">
               <!--  <select name="level" lay-verify="required" ng-model="field.level" lay-filter="level" ng-options="v.level_id as v.level_name for v in group" ng-selected="v.level_id==field.level"> -->
                <select name="level" lay-verify="required" ng-model="field.level" lay-filter="level" id="level">
                    <option value="">请选择类型</option>
                    <option ng-model="field.level" ng-value="0">商户</option>
                    <option ng-model="field.level" ng-value="2">商户代理</option>
                </select>  
            </div>
        </div> 
        <div class="layui-form-item" id="agentid" style="display: none;">
            <label class="layui-form-label">商户代理ID</label>
            <div class="layui-input-4">
                <input type="text" name="agentid" ng-model="field.agentid" placeholder="{:lang('pleaseEnter')}商户代理ID" class="layui-input">
            </div>
        </div>  
        <div class="layui-form-item">
            <label class="layui-form-label">商户名称</label>
            <div class="layui-input-4">
                <input type="text" name="name" ng-model="field.name" lay-verify="required" placeholder="{:lang('pleaseEnter')}商户名称" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label">手续费 %</label>
            <div class="layui-input-4">
                <input type="text" name="lv" ng-model="field.lv" lay-verify="required" placeholder="{:lang('pleaseEnter')}手续费" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux"><span class="red">%依次为【微信|支付宝|银行卡】,以“|”隔开</span></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-4">
                <input type="text" name="username" ng-model="field.username" lay-verify="required" placeholder="{:lang('pleaseEnter')}联系人姓名" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-4">
                <input type="text" name="mobile" ng-model="field.mobile" lay-verify="required" placeholder="{:lang('pleaseEnter')}联系方式" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-4"> 
                <input type="text" name="password" placeholder="输入登录{:lang('pwd')}，默认为手机号" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label">商户URL</label>
            <div class="layui-input-4">
                <input type="text" name="url" ng-model="field.url" placeholder="{:lang('pleaseEnter')}商户URL，可不填" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">APPKEY</label>
            <div class="layui-input-4">
                <input type="text" name="appkey" ng-model="field.appkey" readonly="readonly" class="layui-input">
            </div>
        </div>
         <div class="layui-form-item">
            <label class="layui-form-label">支付密码</label>
            <div class="layui-input-4">
                <input type="text" name="paypwd" class="layui-input"  placeholder="{:lang('pleaseEnter')}支付密码，不填则默认为123456" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">押金</label>
            <div class="layui-input-4">
                <input type="text" name="deposit" ng-model="field.deposit" class="layui-input" placeholder="{:lang('pleaseEnter')}押金，可不填">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单笔提现金额</label>
            <div class="layui-input-4">
                <input type="text" name="one_cash" ng-model="field.one_cash" class="layui-input" placeholder="{:lang('pleaseEnter')}单笔提现金额，可不填">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否审核</label>
            <div class="layui-input-block">
                <input type="radio" name="open" ng-model="field.open" ng-checked="field.open==1" ng-value="1" title="{:lang('open')}">
                <input type="radio" name="open" ng-model="field.open" ng-checked="field.open==0" ng-value="0" title="{:lang('close')}">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label">绑定币种</label>
            <div class="layui-input-block">
            {volist name="cionlist" id="vo"}
                <input type="checkbox"  lay-filter="cionss"  id="cions{$vo.id}" name="cions" value="{$vo.id}" title="{$vo.name}">  
            {/volist}
            
            </div>
        </div> 
        
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商户简介</label>
            <div class="layui-input-block">
                <textarea ng-model="field.content" placeholder="请输商户简介" name="content" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <button href="javascript：void(0)" onclick="window.history.go(-1);" class="layui-btn layui-btn-primary">返回</button>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script src="/static/common/js/angular.min.js"></script>
<script>
    var m = angular.module('hd',[]);
    m.controller('ctrl',['$scope',function($scope) { 
        $scope.field = '{$info|raw}'!='null'?{$info|raw}:{id:'',name:'',url:'',open:1,content:''};
        layui.use(['form', 'layer'], function () {
            var form = layui.form, $ = layui.jquery;
            var cions = {$selectcion|raw};  
            $(cions).each(function (i,o) {
                cionsss="#cions"+o;
                $(cionsss).attr("checked", "checked");   
            });  
            form.render('checkbox');
            form.on('submit(submit)', function (data) {    
                var cionss = [];    
                $("input[name=cions]").each(function(i){
                    if(this.checked){
                        value=$(this).val();
                        cionss +=value+',';
                    } 
                }) 
                // 提交到方法 默认为本身
                data.field.cions = cionss; 
                data.field.id = $scope.field.id; 
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            });
            // form.render('select');
            // alert($("#level").val());
            var levenid_ = $("#level").val().split(":")[1];
            if(levenid_==0){
                $("#agentid" ).css({display:"block"}); 
            }
            form.on('select(level)', function(data) {
                var levenid = data.value.split(":")[1];
                if(levenid==0){  
                    $("#agentid" ).css({display:"block"});   
                }else{
                    $("#agentid" ).css({display:"none"}); 
                }
            });
        });
    }]);
</script>